package com.search;

import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.Node;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class RegexChinese {
    public static void main(String[] args) throws IOException {
        String url = "https://www.aibj.fun/thread-14502-1-3.html";
        //String url = "https://www.google.com/";
        /*System.setProperty("http.proxyHost", "127.0.0.1");
        System.setProperty("http.proxyPort", "10809");*/
        //String url = "https://blog.csdn.net/chen15369337607/article/details/103822464";
        Connection connection = Jsoup.connect(url).proxy("127.0.0.1",10809);
        Document document = connection.get();
        Elements siblingElements = document.getElementsByClass("typeoption").get(0).siblingElements();
        Element tf = document.getElementsByClass("t_f").get(0);

        String context = tf.html();
        String chinesePattern = "[\\u4e00-\\u9fa5]+";
        Pattern pattern = Pattern.compile(chinesePattern);
        Matcher matcher = pattern.matcher(context);
        StringBuilder builder = new StringBuilder();

        // 提取并打印所有匹配的中文字符
        while (matcher.find()) {
            builder.append(matcher.group()+",");
        }

        System.out.println(builder.toString());
        List<TextNode> nodes = tf.textNodes();
        for(Node node:nodes){
            //System.out.println(node.toString());
        }
        int index = document.getElementsByClass("typeoption").get(0).siblingIndex();
        Element first = document.getElementsByClass("typeoption").get(0).firstElementSibling();
        Element next = document.getElementsByClass("typeoption").get(0).nextElementSibling();
        Elements nexts =  document.getElementsByClass("typeoption").get(0).nextElementSiblings();
        System.out.println("ggggggggggggggggggggggg");

    }
}
